﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using YouErYuanBLL;
using YouErYuanModels;

namespace YouErYuanManage.Controllers
{
    public class NewsPublishController : Controller
    {
 
        [YouErYuanManage.Filter.IsLogin]
        public string InsertPublish()
        {
            SchoolNewsBLL npBLL = new SchoolNewsBLL();
            SchoolNews News = new SchoolNews();
            News.headImgURL = Request["headImgURL"];
            News.source = Request["source"];
            News.title = Request["title"];
            string contentWZ = Request["contentWZ"];
            News.shcoolID  = (HttpContext.Session["user"] as Teacher).Schoolid;
            //解码
            byte[] jmBytes = Convert.FromBase64String(contentWZ);
            string decodeContent = Encoding.UTF8.GetString(jmBytes);
            //处理百度编辑器里面的图片
            string managerWWW = System.Configuration.ConfigurationManager.AppSettings["youeryuanAppManagerWWW"];
            if (decodeContent.Contains("/manager/ueditorImg"))
            {
                string imgAllHttpURL = managerWWW + "/manager/ueditorImg";
                decodeContent = decodeContent.Replace("/manager/ueditorImg", imgAllHttpURL);
            }
            News.contentWZ = decodeContent;
            int count = npBLL.Insert(News);
            return CommonLib.CommonMethod.FormatJsonObj(count, "");
        }        
    }
}